package com.gold.gauss.service;

import java.sql.DriverManager;

/**
 * Created by Gary on 2019-12-24.
 *
 * @author Gary
 * @version 0.0.1
 * @date 2019-12-24
 * @since 0.0.1
 */
public class ConnectionManager {
    public static java.sql.Connection getConnection(String jdbcUrl, String userName, String password) {
        //驱动类。
        String driver = "org.postgresql.Driver";
        //数据库连接描述符。
        String sourceURL = jdbcUrl;
        java.sql.Connection conn = null;
        try {
            //加载驱动。
            Class.forName(driver);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        try {
            //创建连接。
            conn = DriverManager.getConnection(sourceURL, userName, password);
            System.out.println("Connection succeed!");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return conn;
    }
}
